package qf.wlh.com.oneprisdent.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import bean.GridViewSpeakerBean;
import qf.wlh.com.oneprisdent.R;

/**
 * Created by zyq on 2016/11/25.
 */

//我是
public class SpeakerGridAdapter extends BaseAdapter {

    private List<GridViewSpeakerBean.DataBean> data=new ArrayList<>();
    private Context context;

    public SpeakerGridAdapter(List<GridViewSpeakerBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data!=null?data.size():0;
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null) {
            view = LayoutInflater.from(context).inflate(R.layout.grid_speak_grid_item, viewGroup, false);
            holder=new ViewHolder();
            holder.imageView= (ImageView) view.findViewById(R.id.grid_spreader_image);
            holder.textView= (TextView) view.findViewById(R.id.grid_spreaker_text);

            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.textView.setText(data.get(i).getNickname());

        Picasso.with(context).load(data.get(i).getPic()).skipMemoryCache().into(holder.imageView);
        return view;
    }

    class ViewHolder{
        TextView textView;
        ImageView imageView;
    }
}
